from django.shortcuts import render_to_response, get_object_or_404
from members.models import Member


# main page(home page)
def index(request):
	

	latest_member_list = Member.objects.all().order_by('id')


####
	#from django.template import Context, loader
	#from django.http import HttpResponse

#	t = loader.get_template('break_ssat/home.html')
#	c = Context({
#		'latest_member_list': latest_member_list,
#	})

#	return HttpResponse(t.render(c))
#### this is totally same with below.   

	# render_to_response shortcut  ->   httpresponse + render functionality
	return render_to_response('members/index.html', {'latest_member_list': latest_member_list})

# member_detail page
def detail(request, member_id):

####

#	from django.http import Http404

#	try:
#		m = Member.objects.get(pk=member_id)
#	except Member.DoesNotExist:
#		raise Http404
#### this is totally same with below.

	# get_object_or_404 shortcut  -> objects.get + raise http404 functionality
	m = get_object_or_404(Member, pk = member_id)

	return render_to_response('members/detail.html', {'member': m})

